package com.liwen.kefu.service.impl;

import ca.krasnay.sqlbuilder.DeleteCreator;
import ca.krasnay.sqlbuilder.InsertCreator;
import ca.krasnay.sqlbuilder.SelectCreator;
import ca.krasnay.sqlbuilder.UpdateCreator;
import club.kingon.sql.builder.SqlBuilder;
import com.liwen.kefu.service.JdbcSqlBuildService;
import org.junit.Test;
import org.junit.experimental.theories.suppliers.TestedOn;
import org.springframework.jdbc.core.PreparedStatementCreator;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author: Liwen
 * @createTime: 2024/11/9
 * @description:
 */
@Component
public class JdbcSqlBuilderServiceImpl implements JdbcSqlBuildService {


    /**
     * 插入
     *
     * @param tableName
     * @param value
     * @return
     */
    @Override
    public PreparedStatementCreator toInsert(String tableName, Map<String, Object> value) {
        InsertCreator insertCreator = new InsertCreator(tableName);
        for (Map.Entry<String, Object> entry : value.entrySet()) {
            if (entry.getValue() != null) {
                insertCreator.setValue(entry.getKey(), entry.getValue());
            }
        }
        //insertCreator.setValue("id", value.get("passportid"));
        return insertCreator;
    }

    /**
     * 更新
     *
     * @param tableName
     * @param value
     * @param key
     * @return
     */
    @Override
    public PreparedStatementCreator toUpdate(String tableName, Map<String, Object> value, String key) {
        UpdateCreator updateCreator = new UpdateCreator(tableName);
        value.forEach(updateCreator::setValue);
        updateCreator.whereEquals(key, value.get(key));
        return updateCreator;
    }

    @Override
    public String toDelete(String tableName, String key, List<String> list) {
        String sql = SqlBuilder.delete(tableName).whereIn(key, list).build();
        return sql;
    }

    @Test
    public void test() {
        String tableName = "t_user";

        List<String> stringList = new ArrayList<>();
        stringList.add("1");
        stringList.add("2");





    }


}
